﻿using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using GeoSketch2.Archaeo;
using GeoSketch2.Core;

namespace GeoSketch2.Test
{
    /// <summary>
    /// The test form
    /// </summary>
    public partial class TestForm : Form
    {
               

        /// <summary>
        /// The test form
        /// </summary>
        public TestForm()
        {
            InitializeComponent();

            List<BaseDrawableObject> GeoObject = new List<BaseDrawableObject>();
            Archaeo.Vars.Setup.DrawableObjects.Point2D.DrawId = true;
            Layer layer1, layer2,layer0;
            ExcavationArea ExcavationUnit = new ExcavationArea(ArchaeoProject.DefaultSiteBounds,null);
            //ExcavationArea.DiggingHeight.Id = 0;
            //ExcavationArea.DiggingHeight.MaxHeight = 112.4;
            Archaeo.Point2D pt1, pt2, pt3, pt4;
            Vertex v1, v2, v3, v4;
            Archaeo.Polyline p;// = new ArchaeoPolyline();
            layer0 = new Layer("Layer 0", Color.Green, new LineType(LineStyle.Solid, 1, 1), true);
            layer1 = new Layer("Layer 1", Color.Red, new LineType(LineStyle.Solid, 1, 1), true);
            layer2 = new Layer("Layer 2", Color.Blue, new LineType(LineStyle.Solid, 2, 1), true);
            Archaeo.GeoTaggedImage img1 = new Archaeo.GeoTaggedImage(GeoSketch2.Core.Vars.TestImages.Img4000x3000EtoileDeMer,
                new RectangleD(20, 50, 50, 50 * (double)3000 / 4000, YAxisDirection.UpSide), layer1,ExcavationUnit);
            pt1 = new Archaeo.Point2D(new Point2D64D(50, 24), layer0, ExcavationUnit);
            pt2 = new Archaeo.Point2D(new Point2D64D(34, 56), layer0, ExcavationUnit);
            pt3 = new Archaeo.Point2D(new Point2D64D(67, 31), layer2, ExcavationUnit);
            pt4 = new Archaeo.Point2D(new Point2D64D(23, 45), layer2, ExcavationUnit);
            v1 = new Vertex(pt1.Position, VertexType.Arc);
            v2 = new Vertex(pt2.Position, VertexType.Arc);
            v3 = new Vertex(pt4.Position, VertexType.Line);
            v4 = new Vertex(pt3.Position, VertexType.Line);
            p = new Archaeo.Polyline(null,layer2, ExcavationUnit);
            p.Vertices.AddRange(new Vertex[]{v1,v2,v3,v4});
            //img1.Object2ImageTransformation = new Transformations.AffineTransformation2D();
            //img1.Object2ImageTransformation.ComputeTranformationFromTargetArea(new Rectangle(new Point(), img1.Image.Size), );
            GeoObject.Add(pt1);
            GeoObject.Add(pt2);
            GeoObject.Add(pt3);
            GeoObject.Add(pt4);
            GeoObject.Add(img1);
            //GeoObject.Add(p);
            Point2D64D[] bounds = new Point2D64D[]{
                pt4.Position,
                pt1.Position,
                pt3.Position,
                pt2.Position};
            

            
            panel_test.Viewport= new Viewport(panel_test,ExcavationUnit.Project);
            //panel_test.Viewport.DoubleBuffereEnabled = true;
            panel_test.Viewport.CurrentExcavationArea = ExcavationUnit;
            panel_test.Viewport.CurrentObjectView = Tools.GetRectangleDBounds(new Point2D64D[]{
                pt1.Position,
                pt2.Position,
                pt3.Position,
                pt4.Position}, YAxisDirection.UpSide);



            panel_test.Viewport.Layers.AddRange(new Layer[] { layer0, layer1, layer2 });
            ExcavationUnit.AvailableLayers.AddRange(new Layer[] { layer0, layer1, layer2 });

            panel_test.Viewport.SetNextLayerId();
            panel_test.Viewport.SortLayers();

            TZoomBox zoombox = new TZoomBox(panel_test.Viewport);
            TPan pan = new TPan(panel_test.Viewport);
            //panel_test.LeftClicTool = zoom;
            //panel_test.RightClicTool = pan;
            //panel_test.Viewport.CurrentDiggingHeight = DiggingHeight;
            panel_test.Viewport.CurrentLayer = layer2;
            GeoObjects = GeoObject;

            nav.DisplayBox = panel_test;
            nav.Parent = this;
            nav.BringToFront();

            TBdraw.DisplayBox = panel_test;
            TBdraw.Parent = this;
            TBdraw.BringToFront();
            //NavigationBar nav = new NavigationBar(panel_test);
            //this.Controls.Add(nav);
            //nav.Show();
        }

        /// <summary>
        /// A class which contains some useful geometric transformations
        /// </summary>
        public List<BaseDrawableObject> GeoObjects
        {
            set
            {
                panel_test.Viewport.GeoObjects = value;
            }
        }

        /// <summary>
        /// A class which contains some useful geometric transformations
        /// </summary>
        public Viewport ViewPort
        {
            set
            {
                panel_test.Viewport = value;
            }
        }
        
    }
}
